<div id="mainContent" class="omega grid_13">

    <?php
    isset($projekt_data) ? $form_title = 'Projekt szerkesztése' : $form_title = 'Projekt felvétele';
    ?>

    <h1><?php echo $form_title ?></h1>

    <?php
    // ha nincs beolvasva adatbázisból, vagy már szerkesztettük
    if (!isset($projekt_data->kiemelt_flag) || $projekt_data->kiemelt_flag != set_value('kiemelt_flag') && set_value('kiemelt_flag') != '') {
        $projekt_data->kiemelt_flag = set_value('kiemelt_flag');
    }
    if (!isset($projekt_data->jelenleg_fut_flag) || $projekt_data->jelenleg_fut_flag != set_value('jelenleg_fut_flag') && set_value('jelenleg_fut_flag') != '') {
        $projekt_data->jelenleg_fut_flag = set_value('jelenleg_fut_flag');
    }
    if (!isset($projekt_data->kiemelt_kep_url) || $projekt_data->kiemelt_kep_url != set_value('kiemelt_kep_url') && set_value('kiemelt_kep_url') != '') {
        $projekt_data->kiemelt_kep_url = set_value('kiemelt_kep_url');
    }
    if (!isset($projekt_data->projekt_kep_url) || $projekt_data->projekt_kep_url != set_value('projekt_kep_url') && set_value('projekt_kep_url') != '') {
        $projekt_data->projekt_kep_url = set_value('projekt_kep_url');
    }
    if (!isset($projekt_data->projekt_nev) || $projekt_data->projekt_nev != set_value('projekt_nev') && set_value('projekt_nev') != '') {
        $projekt_data->projekt_nev = set_value('projekt_nev');
    }
    if (!isset($projekt_data->projekt_leiras) || $projekt_data->projekt_leiras != set_value('projekt_leiras') && set_value('projekt_leiras') != '') {
        $projekt_data->projekt_leiras = set_value('projekt_leiras');
    }

    // a két radio buttonnak mindenképpen kell adni értéket, ha nincs neki.
    if ($projekt_data->kiemelt_flag == "") {
        $projekt_data->kiemelt_flag = "0";
    }
    if ($projekt_data->jelenleg_fut_flag == "") {
        $projekt_data->jelenleg_fut_flag = "0";
    }

    if (!isset($projekt_data->projekt_id)) {
        echo form_open("admin/projektek/add_projekt");
        // ha új projekt, nem lesz user_id így csinálunk egyet, mert kell a scripthez
        $projekt_data->projekt_id = "''";
    } else {
        echo form_open("admin/projektek/update_projekt/$projekt_data->projekt_id");
    }
    ?>



    <fieldset>
        <legend>Add meg a projekt adatait. A csilaggal jelölt mezők kitöltését ne felejtsd el!</legend>
        <label class="lf must">
            <span class="inputLabel">
                Projekt neve
            </span>
            </span>
            <span class="inputWrap">
                <input class="" type="text" name="projekt_nev" value="<?php echo $projekt_data->projekt_nev ?>" />
            </span>
        </label>


        <label class="must">
            <span class="inputLabel">
                A projekt fejlécképe
            </span>
            <span class="field_desc">(pontosan 915x200px méretű kép) 

                <?php if ($projekt_data->kiemelt_kep_url != ""): ?>
                    <span class="deleteInfo" id="fejlec_kep_url_visible" style="display: none;"></span>
                <?php else: ?>
                    <span class="deleteInfo" id="fejlec_kep_url_visible"> - nincs megadva.</span>
                <?php endif; ?>
            </span>


            <span class="inputWrap">
                <!-- direkt van itt a loader a gomb előtt -->

                <input id="fejlec_browse_picture_button" class="button ui-button ui-widget ui-state-default ui-corner-all" type="submit" value="Kép tallózása" />
                <img id="fejlec_file_uploader_waiting" class="loader" src="<?php echo base_url(); ?>admin_style/assets/loadanim.gif" width="16" height="16" alt="load" style="display: none;" />
                <input id="fejlec_kep_url" name="projekt_kep_url" value="<?php echo $projekt_data->projekt_kep_url ?>" type="hidden" class="lf deleteValue" />

            </span>
            <span class="fejlec_preview previewIt">
                <a href="#" class="deleteBtn" style="display: none;">
                    <img  src="<?php echo base_url(); ?>admin_style/assets/delete.png" width="40" height="40" alt="Törlés"  />
                </a>
                <img id="fejlec_image_preview" class="deletePic" <?php
                if ($projekt_data->projekt_kep_url != "")
                    echo "src=\"$projekt_data->projekt_kep_url\"";
                else
                    echo "style=\"display: none;\" src=\"\"";
                ?> width="" height="" />
            </span>
        </label>

        <div id="fejlec_image_browser_window" title="Galéria">
            <div id="fejlec_image_browser" class="videoPreview">
            </div>
        </div>

        <label class="must">
            <span class="inputLabel">
                A projekt matricája
            </span>
            <span class="field_desc">(pontosan 167x80px méretű kép)


                <?php if ($projekt_data->kiemelt_kep_url != ""): ?>
                    <span class="deleteInfo" id="matrica_kep_url_visible" style="display: none;"> - nincs megadva.</span>
                <?php else: ?>
                    <span class="deleteInfo" id="matrica_kep_url_visible"> - nincs megadva.</span>
                <?php endif; ?>
            </span>

            <span class="inputWrap">
                <!-- direkt van itt a loader a gomb előtt -->

                <input id="matrica_browse_picture_button" class="button ui-button ui-widget ui-state-default ui-corner-all" type="submit" value="Kép tallózása" />
                <img id="matrica_file_uploader_waiting" class="loader" src="<?php echo base_url(); ?>admin_style/assets/loadanim.gif" width="16" height="16" alt="load" style="display: none;" />
                <input id="matrica_kep_url" name="kiemelt_kep_url" value="<?php echo $projekt_data->kiemelt_kep_url ?>" type="hidden" class="lf deleteValue" />

            </span>
            <span class="matrica_preview previewIt">
                <a href="#" class="deleteBtn" style="display: none;">
                    <img src="<?php echo base_url(); ?>admin_style/assets/delete.png" width="40" height="40" alt="Törlés"  />
                </a>
                <img id="matrica_image_preview" class="deletePic" <?php
                if ($projekt_data->kiemelt_kep_url != "")
                    echo "src=\"$projekt_data->kiemelt_kep_url\"";
                else
                    echo "style=\"display: none;\" src=\"\"";
                ?> width="" height="" />
            </span>
        </label>

        <div id="matrica_image_browser_window" title="Galéria">
            <div id="matrica_image_browser" class="videoPreview">
            </div>
        </div>


        <div class="radioSetContainer" >
            <span class="inputLabel">
                Kiemelt legyen a projekt?
            </span>
            <span class="inputWrap">
                <div id="radioYesNo" class="radioSet">
                    <input type="radio" id="igen" name="kiemelt_flag" value="1" 
                    <?php
                    if ($projekt_data->kiemelt_flag == '1')
                        echo "checked=\"checked\""
                        ?>/>
                    <label for="igen">igen</label>
                    <input type="radio" id="nem" name="kiemelt_flag" value="0" 
                    <?php
                    if ($projekt_data->kiemelt_flag == '0')
                        echo "checked=\"checked\""
                        ?>/>
                    <label for="nem">nem</label>

                </div>
            </span>
        </div>

        <div class="radioSetContainer" >
            <span class="inputLabel">
                Jelenleg fut a projekt?
            </span>
            <span class="inputWrap">
                <div id="radioActual" class="radioSet">
                    <input type="radio" id="aktualis" name="jelenleg_fut_flag" value="1" 
            <?php if ($projekt_data->jelenleg_fut_flag == '1')
                echo "checked=\"checked\""
                ?>/>
                    <label for="aktualis">igen</label>
                    <input type="radio" id="korabbi" name="jelenleg_fut_flag" value="0" 
                    <?php
                    if ($projekt_data->jelenleg_fut_flag == '0')
                        echo "checked=\"checked\""
                        ?>/>
                    <label for="korabbi">nem</label>
                </div>
            </span>
        </div>


        <label class="textAreaHolder">
            <span class="inputLabel">
                Projekt leírás
            </span>
            <textarea name="projekt_leiras" class="maxTextarea" id="tinymce_textarea"><?php echo $projekt_data->projekt_leiras; ?></textarea>
        </label>
    </fieldset>
    <input class="button ui-button ui-widget ui-state-default ui-corner-all" type="submit" value="Mentés" />
</form>

</div>

<script src="<?php echo base_url() ?>admin_style/js/tiny_mce/tiny_mce.js" type="text/javascript" charset="utf-8"></script>
<script src="<?php echo base_url() ?>admin_style/js/tiny_mce/jquery.tinymce.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">    
    // tinmyce
    $(document).ready(function() {   
        // tinymce
        $('#tinymce_textarea').tinymce({
            // General options
            // General options
            mode : "textareas",
            theme : "advanced",
            plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

            // Theme options
            theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
            theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,|,forecolor,backcolor",
            theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr, |,ltr,rtl,|,fullscreen",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_statusbar_location : "bottom",
            theme_advanced_resizing : true,
            width: "100%",
            height: "400",
            language : "hu",
            remove_script_host : false,
            convert_urls : false,
            
            file_browser_callback : function(field_name, url, type, win) {
                var w = window.open('<?php echo site_url('admin/gallery/get_fullpage_gallery/projektek') ?>', null, 'width=600,height=500');
                // Save required parameters in global variables of window (not the best solution, can offer better?)
                // else you can pass parameters using GET and than parse them in elfinder.html
                w.tinymceFileField = field_name;
                w.tinymceFileWin = win;
            }
        });
        
        // képméret lekérdezése
        function get_image_size(url){
            var size = false;
            $.ajax({
                url: '<?php echo site_url('admin/gallery/get_picture_size'); ?>',
                data: {
                    // elküldjük az id-t, mert adatokat várunk vissza
                    image_url : url
                },
                dataType: 'json',
                type: 'post',
                async: false,
                success: function (data) {
                    size = data;
                },
                error: function(XMLHttpRequest, textStatus, errorThrown){
                    alert("Hiba történt: " + errorThrown.toString());
                }
            });
            return size;
        }
        
        // fejléc kép tallózás
        $('#fejlec_browse_picture_button').click(function() {
            $("#fejlec_file_uploader_waiting").show(500);  
            init_fejlec_finder();
            $( "#fejlec_image_browser_window" ).dialog('open');

            file_dialog = $( "#fejlec_image_browser_window" ).dialog({
                resizable: false,
                width:640,
                height:480,
                modal: true,
                beforeClose: function(){
                    $("#fejlec_file_uploader_waiting").hide(500); 
                }
            }); 
            
            return false;
        });
        
        // matrica kép tallózás
        $('#matrica_browse_picture_button').click(function() {
            $("#matrica_file_uploader_waiting").show(500);  
            init_matrica_finder();
            $( "#matrica_image_browser_window" ).dialog('open');

            file_dialog = $( "#matrica_image_browser_window" ).dialog({
                resizable: false,
                width:640,
                height:480,
                modal: true,
                beforeClose: function(){
                    $("#matrica_file_uploader_waiting").hide(500); 
                }
            }); 
            
            return false;
        });
        
        // finder inicializálás PROJEKT FEJLÉCKÉPRE
        function init_fejlec_finder(){
            $('#fejlec_image_browser').elfinder({
                url : '<?php echo site_url('admin/gallery/connect/projektek') ?>',
                lang : 'hu',
                places : '',
                autoReload : '10',
                closeOnEditorCallback : false,
                editorCallback : function(url){
                    // get image info
                    var image_size = get_image_size(url);
                    // check image size
                    if(image_size.width == '915' && image_size.height == '200'){
                        $("#fejlec_image_preview").show(500).attr('src', url);
                        $("#fejlec_kep_url").val(url);
                        $("#fejlec_kep_url_visible").hide().html("");
                        $( "#fejlec_image_browser_window" ).dialog("close");
                    }else{
                        $("#fejlec_kep_url_visible").show(500).html("nincs megadva.");
                        $("#fejlec_kep_url").val("");
                        $("#fejlec_image_preview").hide(500).attr('src', '');
                        alert('A kiválaszott kép mérete nem megfelel\u0151. A megfelel\u0151 képméret: 915x200');
                    }
                }
            });
        }
        
        // finder inicializálás PROJEKT MATRICÁRA
        function init_matrica_finder(){
            $('#matrica_image_browser').elfinder({
                url : '<?php echo site_url('admin/gallery/connect/projektek') ?>',
                lang : 'hu',
                places : '',
                autoReload : '10',
                closeOnEditorCallback : false,
                editorCallback : function(url){
                    // get image info
                    var image_size = get_image_size(url);
                    // check image size
                    if(image_size.width == '167' && image_size.height == '80'){
                        $("#matrica_image_preview").show(500).attr('src', url);
                        $("#matrica_kep_url").val(url);
                        $("#matrica_kep_url_visible").hide().html("");
                        $( "#matrica_image_browser_window" ).dialog("close");
                    }else{
                        $("#matrica_kep_url_visible").show(500).html("nincs megadva.");
                        $("#matrica_kep_url").val("");
                        $("#matrica_image_preview").hide(500).attr('src', '');
                        alert('A kiválaszott kép mérete nem megfelel\u0151. A megfelel\u0151 képméret: 167x80');
                    }
                }
            });
        }

    });
    
</script>